﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using CastleDefender.ConfigFolder;
using CastleDefender.Object;
using Microsoft.Xna.Framework.Graphics;
using CastleDefender.Platform.ScreenBehavior;

namespace CastleDefender.Platform.GameScene
{
    public partial class GamePause : GameScene
    {

        #region VARIABLE

        protected Button btnContinue;
        protected Button btnMenu;
        protected int intChoose;
        protected TouchBehavior tbTouch;

        #endregion

        #region CONSTRUCTOR

        public GamePause(Game myGame, ref TouchBehavior touch)
            : base(myGame, Config.FolderBackgrounds + "Pause")
        {
            //Load hình ảnh các nút bấm
            Texture2D textureButtonContinue = myGame.Content.Load<Texture2D>(Config.FolderButtons + "Continue");
            Vector2 posButtonContinue = new Vector2((Config.ScreenSize.X - 195) / 2, (Config.ScreenSize.Y - textureButtonContinue.Height) / 2);
            btnContinue = new Button(myGame, ref textureButtonContinue, 195, 50, true, false, posButtonContinue);
                
            Texture2D textureButtonMenu = myGame.Content.Load<Texture2D>(Config.FolderButtons + "Menu");
            btnMenu = new Button(myGame, ref textureButtonMenu, 195, 50, true, false,
                new Vector2((Config.ScreenSize.X - 195) / 2, posButtonContinue.Y + 55));

            tbTouch = touch;
            lstComponents.Add(btnContinue);
            lstComponents.Add(btnMenu);

        }

        #endregion

        #region PUBLIC METHOD

        public override void Show()
        {
            intChoose = -1;
            base.Show();
        }

        public override void Hide()
        {
            base.Hide();
        }

        public override void Update(GameTime gameTime)
        {
            if (Enabled && Visible)
            {
                UpdateButton();
                base.Update(gameTime);
            }
        }

        #endregion

        #region PRIVATE METHOD

        private void UpdateButton()
        {
            if (tbTouch.IsMoved || tbTouch.IsPressed)
            {
                Point pos = new Point((int)tbTouch.PosCurrent.X, (int)tbTouch.PosCurrent.Y);

                btnContinue.GetTouchPosition(pos);
                btnMenu.GetTouchPosition(pos);

                //Nút bấm tiếp tục trò chơi
                if (btnContinue.Touch)
                {
                    btnContinue.Active = true;
                }
                else
                {
                    btnContinue.Active = false;
                }

                //Nút bấm trở về menu chính
                if (btnMenu.Touch)
                {
                    btnMenu.Active = true;
                }
                else
                {
                    btnMenu.Active = false;
                }
            }

            if (tbTouch.IsKeyUp)
            {
                //Khi chọn vào nút bấm tiếp tục
                if (btnContinue.Touch)
                {
                    intChoose = 0;
                    //Tắt nút bấm khi đã thực thi
                    btnContinue.Active = false;
                    btnContinue.GetTouchPosition(Point.Zero);
                }

                //Khi chọn vào nút bấm trở về menu
                if (btnMenu.Touch)
                {
                    intChoose = 1;
                    //Tắt nút bấm khi đã thực thi
                    btnMenu.Active = false;
                    btnMenu.GetTouchPosition(Point.Zero);
                }
            }
 
        }
 
        #endregion

        #region PUBLIC PROPERTIES

        //Trả giá trị intChoose
        public int SelectedIndex
        {
            get { return intChoose; }
        }

        #endregion

    }
}
